
public class lotInfo {
	private int ID;
	private String Name;
	private String Address;
	private int[] dayFee;	// 0: MTWTF, 2: Sat, 4: Sun (e.g. 7 when it is always free [1 1 1])
	private int monthFee;
	
	private int Nrule=0;
	private double[][] hourFee;
	private int[] days;
	
	public void initialize(int n, String str, String addr, int f1, int f2, int f3){
		this.ID = n;
		this.Name = str;
		this.Address = addr;
		/*this.dayFee = new int[7];
		
		for (int i=0; i<5; i++){
			this.dayFee[i] = f1;
		}
		this.dayFee[5] = f2;
		this.dayFee[6] = f2;*/
		
		this.dayFee = new int[3];
		this.dayFee[0] = f1;
		this.dayFee[1] = f2;
		this.dayFee[2] = f2;
		
		this.monthFee = f3;
		
		Nrule = 0;
		hourFee = new double[100][3];
		days = new int[100];
	}
	
	public void addRule(String day, int start, int end, double fee){
		
		//hourFee[Nrule][0] = day;
		if(day.indexOf("MTWTF")!=-1)days[Nrule]+=1;
		if(day.indexOf("Sat")!=-1)days[Nrule]+=2;
		if(day.indexOf("Sun")!=-1)days[Nrule]+=4;
		
		hourFee[Nrule][0] = start;
		hourFee[Nrule][1] = end;
		hourFee[Nrule][2] = fee;
		Nrule++;
	}
	
	public int getID()
	{
		return this.ID;
	}
	public String getAddr()
	{
		return this.Address;
	}
	public double getFee(int day, int start, int end){
		
		double TotalFee=0.0;
		int diff = end - start;
		for( int i=0; i < this.Nrule; i++){
			if(day == 1){
				if(this.days[i]%2 ==1){
					if(hourFee[i][0] <=start &&hourFee[i][1] >=end){
						return hourFee[i][2]*(end-start);
					}else if(hourFee[i][0] >=start &&hourFee[i][1] <=end){
						TotalFee += (hourFee[i][1]-hourFee[i][0])*hourFee[i][2];
						diff -=hourFee[i][1]-hourFee[i][0];
					}
					else if(hourFee[i][0] >=start &&hourFee[i][1] >=end){
						TotalFee += (end -hourFee[Nrule][0])*hourFee[i][2];
						diff -=end -hourFee[Nrule][0];
					}
					else if(hourFee[i][0] <=start &&hourFee[i][1] <=end){
						TotalFee += (hourFee[Nrule][1]-start)*hourFee[i][2];
						diff -= hourFee[Nrule][1]-start;
					}
					else{
						System.err.println("invalid start and end");
					}
				}
			}else if(day ==2){
				if(this.days[i]%4 ==3 || this.days[i]%4 ==2 ){
					if(hourFee[i][0] <=start &&hourFee[i][1] >=end){
						return hourFee[i][2]*(end-start);
					}else if(hourFee[i][0] >=start &&hourFee[i][1] <=end){
						TotalFee += (hourFee[i][1]-hourFee[i][0])*hourFee[i][2];
						diff -=hourFee[i][1]-hourFee[i][0];
					}
					else if(hourFee[i][0] >=start &&hourFee[i][1] >=end){
						TotalFee += (end -hourFee[Nrule][0])*hourFee[i][2];
						diff -=end -hourFee[Nrule][0];
					}
					else if(hourFee[i][0] <=start &&hourFee[i][1] <=end){
						TotalFee += (hourFee[Nrule][1]-start)*hourFee[i][2];
						diff -= hourFee[Nrule][1]-start;
					}
					else{
						System.err.println("invalid start and end");
					}					
				}
			}else if(day ==4){
				if(this.days[i] >=4){
					if(hourFee[i][0] <=start &&hourFee[i][1] >=end){
						return hourFee[i][2]*(end-start);
					}else if(hourFee[i][0] >=start &&hourFee[i][1] <=end){
						TotalFee += (hourFee[i][1]-hourFee[i][0])*hourFee[i][2];
						diff -=hourFee[i][1]-hourFee[i][0];
					}
					else if(hourFee[i][0] >=start &&hourFee[i][1] >=end){
						TotalFee += (end -hourFee[Nrule][0])*hourFee[i][2];
						diff -=end -hourFee[Nrule][0];
					}
					else if(hourFee[i][0] <=start &&hourFee[i][1] <=end){
						TotalFee += (hourFee[Nrule][1]-start)*hourFee[i][2];
						diff -= hourFee[Nrule][1]-start;
					}
					else{
						System.err.println("invalid start and end");
					}
				}
			}else{
				System.err.println("Invalid input for day.");
				return 0.0;
			}
			if(diff == 0 )break;
		}
		if(diff!=0) return this.dayFee[(int)(day/2)];
		return TotalFee;
	}
	public int tointDay(String day){
		int iDay = 0 ;
		if(day.indexOf("MTWTF") != -1){
			iDay += 1;
		}
		if(day.indexOf("Sat") != -1){
			iDay += 2;
		}
		if(day.indexOf("Sun") != -1){
			iDay += 4;
		}
		return iDay;
	}
}
